/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.ui.function.window.secretchat;

import java.awt.Font;
import java.awt.Graphics;

import lineage.ui.L1Panel;
import lineage.ui.customize.L1Font;

/**
 * 密语聊天框显示'标题'字串用的面板.
 * 
 * @version 2014年2月26日下午7:36:03
 * @author jrwz
 */
public final class L1PanelTitle extends L1Panel {
    private static final long serialVersionUID = 749790947708691537L;

    private String tempText;

    /**
     * 静态初始化器，由JVM来保证线程安全.
     */
    private static class Holder {
        static L1PanelTitle instance = new L1PanelTitle();
    }

    /**
     * 取得该类的实例.
     */
    public static L1PanelTitle getInstance() {
        return Holder.instance;
    }

    private L1PanelTitle() {
        _x = 145;
        _y = 15;
        _width = 329;
        _height = 24;
        font();
        setOpaque(false); // 设置为透明

        init(true);
    }

    /**
     * 设置字体.
     */
    private void font() {
        L1Font.setFont(Font.PLAIN, 14.0f);
        setFont(L1Font.getFont()); // 设置字体
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        StringBuilder sb = new StringBuilder();
        sb.append("你正在与 (");
        sb.append(tempText);
        sb.append(") 密语聊天");
        g.drawString(sb.toString(), 10, 18); // 在指定位置绘制文本
    }

    /**
     * 取得临时字串.
     * 
     * @return 临时字串
     */
    public String getTempText() {
        return tempText;
    }

    /**
     * 设置临时字串.
     * 
     * @param tempText
     *            - 临时字串
     */
    public void setTempText(String tempText) {
        this.tempText = tempText;
        super.repaint(); // 重绘此组件
    }
}
